package com.atguigu.gmall.product;

import com.atguigu.gmall.common.constant.RedisConst;
import com.atguigu.gmall.product.prop.MinIOProperties;
import org.mybatis.spring.annotation.MapperScan;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.ComponentScan;

/**
 * @author mgx
 * @version 1.0
 * @description: TODO
 * @date 2022/10/19 16:13
 */
@SpringBootApplication
@ComponentScan(basePackages = {"com.atguigu.gmall"})
@EnableDiscoveryClient // 注册到nacos注册中心
@EnableConfigurationProperties(value = {MinIOProperties.class})
public class ServiceProductApplication implements CommandLineRunner {

    @Autowired
    private RedissonClient redissonClient;


    public static void main(String[] args) {
        SpringApplication.run(ServiceProductApplication.class, args);
    }

    /**
     * 初始化布隆过滤器
     * @param args
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
        RBloomFilter<Object> bloomFilter = redissonClient.getBloomFilter(RedisConst.SKU_BLOOM_FILTER);
        // 初始化数据总量规模和可承受误判率
        bloomFilter.tryInit(100000, 0.01);
    }
}
